package main_com.mapper;


import main_com.pojo.LookFriendBean;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

@Mapper
public interface FriendMapper {

    @Select("select * from friends where name = #{name} and username = #{userName}")
    ArrayList<LookFriendBean> getFriendByNameAndUserName(String name, String userName);

    @Select("select * from friends where username = #{userName}")
    ArrayList<LookFriendBean> getFriendByUserName(String userName);

    @Select("select * from friends where name = #{name}")
    ArrayList<LookFriendBean> getFriendByName(String name);

    @Select("select count(*) from friends where name = #{name}")
    int findFriendByName(String name);

    @Select("select count(*) from friends where name = #{name} and username = #{userName}")
    int findFriendByNameAndUserName(String name, String userName);

    @Select("select count(*) from friends where name = #{name} and username = #{userName} and phone=#{number}")
    int findFriendByNameAndUserNameNumber(String name, String userName, String number);

    @Select("select * from friends where name = #{name} and username = #{userName} and phone=#{number}")
    ArrayList<LookFriendBean> getFriendByNameAndUserNameNumber(String name, String userName, String number);

    @Update("update friends set phone=#{phone},email=#{email},workPlace=#{workPlace},place=#{place},QQ=#{QQ} where name=#{name} and userName=#{userName}")
    void updateFriend(LookFriendBean friend);

    @Insert("insert into friends values(#{userName}, #{name}, #{phone}, #{email}, #{workPlace}, #{place}, #{QQ})")
    void addFriend(LookFriendBean friend);

    @Delete("delete from friends where name=#{name} and userName=#{userName}")
    void deleteFriendByNameAndUserName(String name, String userName);

    @Delete("delete from friends where name=#{name} and userName=#{userName} and phone=#{number}")
    void deleteFriendByNameAndUserNameNumber(String name, String userName, String number);

    // 分页查询
    @Select("select * from friends where username = #{userName} limit #{offset}, #{pageSize}")
    ArrayList<LookFriendBean> getFriendByUserNameWithPagination(@Param("userName") String userName, @Param("offset") int offset, @Param("pageSize") int pageSize);

    // 查询总记录数
    @Select("select count(*) from friends where username = #{userName}")
    int getTotalFriendCount(String userName);

    @Select("select count(*) from friends where phone = #{phone}")
    int findFriendByPhone(String phone);

    @Select("select * from friends where phone = #{phone}")
    ArrayList<LookFriendBean> getFriendByPhone(String phone);

    @Update("update friends set email=#{email},workPlace=#{workPlace},place=#{place},QQ=#{QQ} where phone=#{phone} and name=#{name}")
    void updateFriendByPhoneAndName(LookFriendBean friend);


}
